﻿#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTcpServer>
#include <QTcpSocket>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();

private:
    void init();
    void consoleColor(QColor color, QString str);
    void tcpBack(QByteArray bt, QTcpSocket* tempSocket);

private slots:
    void newCon(); // 创建新的连接
    void msgBack(QTcpSocket*); // 向客户端返回数据
    void refuseBack(QTcpSocket*); // 处理断开连接的事宜
    void tcpInfoHanle(QTcpSocket*); // 客户端信息处理
    void tcpInfoUse(QTcpSocket* tempSocket, QString tempStr);
    void gameStart();

    void on_pushButton_clicked();

private:
    Ui::Widget *ui;
    QTcpServer* m_tcpServer;
    QTcpSocket* m_tcpSocket_p1;
    QString m_IP_p1;
    QTcpSocket* m_tcpSocket_p2;
    QString m_IP_p2;
    bool m_p1IsReady; // 服务器是否已经获得所有玩家的信息
    bool m_p2IsReady;
    bool m_isInit;
};

#endif // WIDGET_H


